package com.song.su.mapper;

import com.song.su.model.CommentUser;
import com.song.su.model.Footer;
import com.song.su.model.PinglunRank;
import com.song.su.model.likeRank;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;
import java.util.List;

@Mapper
public interface CommentMapper {

    @Insert("insert into comment (account_id,accountname,comtitle,comcontext,gmt_create,gmt_modified,bookid,likecount) values (#{account_Id},#{accountName},#{comTitle},#{comContext},#{gmtCreate},#{gmtModified},#{bookId},0)")
    void create(CommentUser commentUser);

    @Select("select * from comment where BOOKID=#{isbn}")
    List<CommentUser> findByIsbn(@Param("isbn") String isbn);

    @Update("update comment set likecount = likecount +1 where accountname=#{accountname} and BOOKID = #{isbn} and comcontext = #{comContext}")
    void Like(@Param("isbn") String isbn,@Param("accountname") String accountname,@Param("comContext") String comContext);

    @Select("select count(*) from comment where BOOKID=#{isbn}")
    int com_count(@Param("isbn") String isbn);

    @Select("select count(ID) com_count ,BOOKID from COMMENT group by BOOKID order by com_count desc")
    List<PinglunRank> pinglunPaihang();

    @Select("select sum(LIKECOUNT) like_count ,BOOKID from COMMENT group by BOOKID order by like_count desc")
    List<likeRank> like_count();

    @Select("select  GMT_CREATE,ACCOUNTNAME,BOOKID,COMCONTEXT from COMMENT  order by LIKECOUNT desc")
    List<Footer> footer();

    @Select("select * from comment")
    List<CommentUser> findAll();

    @Delete("delete from comment where id=#{id}")
    void delectColumn(@Param("id") int id);
}
